﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Management;
using System.Text;
using System.Threading.Tasks;

namespace Oliving.Common.PcWinHelper
{
    public static class PcWinBaseHelper
    {
        public static string GetNCZYL()
        {

            double zyl = (GetNC() - GetKYNC()) / GetNC() * 100;
            return Math.Round(zyl, 2).ToString();
        }

        public static double GetKYNC()
        {
            double totalCapacity = 0;
            ObjectQuery objectQuery = new ObjectQuery("select * from Win32_PerfRawData_PerfOS_Memory");
            ManagementObjectSearcher searcher = new
           ManagementObjectSearcher(objectQuery);
            ManagementObjectCollection vals = searcher.Get();
            foreach (ManagementObject val in vals)
            {
                totalCapacity += System.Convert.ToDouble(val.GetPropertyValue("Availablebytes"));
            }
            double ramCapacity = totalCapacity / 1048576;
            return ramCapacity;
        }

        public static double GetNC()
        {
            double totalCapacity = 0;
            ObjectQuery objectQuery = new ObjectQuery("select * from Win32_PhysicalMemory");
            ManagementObjectSearcher searcher = new
            ManagementObjectSearcher(objectQuery);
            ManagementObjectCollection vals = searcher.Get();
            foreach (ManagementObject val in vals)
            {
                totalCapacity += System.Convert.ToDouble(val.GetPropertyValue("Capacity"));
            }
            double ramCapacity = totalCapacity / 1048576;
            return ramCapacity;
        }


    }
}
